#include <bits/stdc++.h>
using namespace std;
int a[100005], b[1000005], c[1000005], n, m, V, L;
vector<pair<int, int>> d;
bool check()
{
    for (int i = 1; i <= L; i++)
        if (b[i] > 0)
            return false;
    return true;
}
int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while (t--)
    {
        d.clear();
        memset(b, 0, sizeof(b));
        memset(c, 0, sizeof(c));
        cin >> n >> m >> L >> V;
        while (n--)
        {
            int x, y, z;
            cin >> x >> y >> z;
            if (z == 0)
            {
                if (y > V)
                {
                    c[L + 1]--;
                    c[x]++;
                    d.push_back({x, L});
                }
            }
            else if (z > 0)
            {
                if (y <= V)
                {
                    c[int(floor((double)(V * V - y * y) / 2 / z + x + 1))]++;
                    d.push_back({int(floor((double)(V * V - y * y) / 2 / z + x + 1)), L});
                }
                else
                {
                    c[x]++;
                    d.push_back({x, L});
                }
                c[L + 1]--;
            }
            else if (y > V)
                c[int(ceil((double)(V * V - y * y) / 2 / z + x - 1)) + 1]--, c[x]++, d.push_back({x - 1, int(ceil((double)(V * V - y * y) / 2 / z + x - 1))});
            for (int i = 1; i <= L; i++)
                b[i] = b[i - 1] + c[i];
            for (int i = 1; i <= L; i++)
                c[i] = b[i] - b[i - 1];
        }
        for (int i = 1; i <= m; i++)
            cin >> a[i];
        int cnt = 0, cnt_1 = 0;
        map<pair<int, int>, bool> e;
        e.clear();
        while (!check())
        {
            int maxn = 0;
            for (int i = 1; i <= m; i++)
                maxn = max(maxn, b[a[i]]);
            for (int i = 1; i <= m; i++)
            {
                if (b[a[i]] == maxn)
                {
                    for (auto &&j : d)
                    {
                        if (!e[j] && j.first <= a[i] && j.second >= a[i])
                        {
                            c[j.first]--;
                            c[j.second + 1]++;
                            e[j] = true;
                            cnt_1++;
                        }
                    }
                    break;
                }
            }
            for (int i = 1; i <= L; i++)
                b[i] = b[i - 1] + c[i];
            cnt++;
        }
        cout << cnt_1 << " " << m - cnt << endl;
    }
    return 0;
}